<template>
  <div class="login">
    <div class="left">欢迎光临红浪漫</div>
    <div class="form">
      <el-form ref="form" :model="form" label-width="100px">
        <el-form-item label="用户名">
          <el-input v-model="form.adminname"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { login } from "@/api/login.js";
export default {
  data() {
    return {
      form: {
        adminname: "",
        password: ""
      }
    };
  },
  methods: {
    onSubmit() {
      login({
        username: this.form.adminname,
        password: this.form.password
      }).then(res => {
        if (res.data.meta.status === 200) {
          // 路由跳转
          this.$router.push("/home/index");
          // 存下来token
          localStorage.setItem("token", res.data.data.token);
        }
      });
    }
  }
};
</script>

<style scoped lang="scss">
@import "@/sass/common.scss";
.login {
  width: $w100; // 使用变量直接用
  height: $w100;
  @include dcc;
  // color: var(--ok);   css中可以在根里面 通过 :root { 这里定义变量  变量名 --xx: 值 } 见index.html的style标签
  // color: var(--ok);  使用根里面定义的变量
  .left {
    width: 70%;
    // height: 1000px;
    height: 609px;
    background-color: rgb(4, 49, 42);
    color: white;
    font-size: 40px;
    text-align: center;
    line-height: 609px;
  }
  .form {
    width: 30%;
    height: 609px;
    @include dcc;
    font-size: 20px;
    font-weight:bolder
    // @include dcc;
    // 设置组件的样式 直接用对应的类名即可
    .el-form {
      width: 400px;
      @include dcc;
    }
  }
}
</style>
